package com.jsmile.cloud.authc.api.req.sys;

import java.util.List;

import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import com.jsmile.mall.api.constants.JSmileConstant;
import com.jsmile.mall.api.exception.ExceptionKit;
import com.jsmile.mall.api.to.BaseUpdateTo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2019年04月01日 04:45:35
 */
@Data
@ApiModel
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ReqSysRoleUpdate extends BaseUpdateTo {

    @ApiModelProperty(value = "角色名称")
    private String roleName;
    @ApiModelProperty(value = "角色code")
    private String roleCode;
    @ApiModelProperty(value = "是否可用 1是 0否")
    private Integer enable;
    @ApiModelProperty(value = "备注")
    private String remark;
    @ApiModelProperty(value = "所属系统")
    private String sysNo;
    @ApiModelProperty(value = "租户id")
    private Long tenantId;

    @ApiModelProperty(value = "角色id")
    private Long roleId;
    @ApiModelProperty(value = "是否删除 1是 0否")
    private List<Long> resourcesIds;

    public void checkRoleResource() {
        ExceptionKit.checkNotNull(this.roleId, "角色id不能为空");
        ExceptionKit.checkArgument(CollectionUtils.isEmpty(this.resourcesIds), "资源集合不能为空");
        ExceptionKit.checkArgument(ObjectUtils.nullSafeEquals(this.roleId, JSmileConstant.JSMILE.SUPER_ADMIN_ROLE_ID), "超级管理员不允许操作");
    }

    public void checkSuperAdmin() {
        ExceptionKit.checkArgument(ObjectUtils.nullSafeEquals(this.roleId, JSmileConstant.JSMILE.SUPER_ADMIN_ROLE_ID), "超级管理员不允许操作");
    }
}
